<?php 
namespace Admin\Model;
use Think\Model;
class SoftwareversionModel extends Model{ 
	/* 软件版本自动验证 */
	protected $_validate = array(
        array('name','require','软件名称必须填写'),
		array('version','require','版本号必须填写'),	
		array('fileid','require','软件还没有上传'),
		array('description','require','版本说明必须填写'),
		array('publish','require','发布时间必须填写'),
    );  
	/* 自动完成规则 */
	protected $_auto = array(
	);
    public function update() {
    	/* 获取数据对象 */
    	$data = $this->create ( $_POST );
    	if (empty ( $data )) {
    		return false;
    	}
    	
    	$file = json_decode(think_decrypt(I('post.fileid')), true);
    	if(!empty($file)){
    		$data['fileid'] = $file['id'];
    	} else {
    		$this->error = '获取上传文件信息失败！';
    		return false;
    	}
    	
    	
    	/* 添加*/
    	if (empty ( $data ['id'] )) {
    		$id = $this->add($data);
    		if (! $id) {
    			$this->error = '新增出错！';
    			return false;
    		}
    	} else {
    		$status = $this->save ($data); 
    		if (false === $status) {
    			$this->error = '更新出错！';
    			return false;
    		}
    	}
    	return $data;
    	
    } 
}